using System;
using LegoBotPrimaAbstractions;
using NUnit.Framework;

namespace LegoBotPrimaTests
{
    [TestFixture]
    public class Ensure_Fixure
    {
        [Test]
        public void IsWithin_Function_Works_With_All_Numeric_Types()
        {
            Assert.DoesNotThrow(() => Ensure.IsWithin(-15, -20, 5, "test int"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(-15, -20, -16, "test int"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(-999, -20, -16, "test int"));

            Assert.DoesNotThrow(() => Ensure.IsWithin(-6f, -12.2f, -5.6f, "test float"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(-5f, -12.2f, -5.6f, "test float"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(-999f, -12.2f, -5.6f, "test float"));

            Assert.DoesNotThrow(() => Ensure.IsWithin(10d, 9.55d, 10.55d, "test double"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(9.54d, 9.55d, 10.55d, "test double"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(10.551d, 9.55d, 10.55d, "test double"));

            Assert.DoesNotThrow(() => Ensure.IsWithin(100m, 99.9m, 1000m, "test decimal"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(100000m, 99.9m, 1000m, "test decimal"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsWithin(-100m, 99.9m, 1000m, "test decimal"));
        }

        [Test]
        public void IsNotZeroOrNegative_Function_Works_With_All_Numeric_Types()
        {
            Assert.DoesNotThrow(() => Ensure.IsNotZeroOrNegative(11, "test int"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(0, "test int"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(-10, "test int"));

            Assert.DoesNotThrow(() => Ensure.IsNotZeroOrNegative(0.15f, "test float"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(0f, "test float"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(-0.10f, "test float"));

            Assert.DoesNotThrow(() => Ensure.IsNotZeroOrNegative(100.0d, "test double"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(0.0d, "test double"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(-999d, "test double"));

            Assert.DoesNotThrow(() => Ensure.IsNotZeroOrNegative(100.0m, "test decimal"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(0.0m, "test decimal"));
            Assert.Throws<ArgumentOutOfRangeException>(() => Ensure.IsNotZeroOrNegative(-999m, "test decimal"));

        }
    }
}